package br.com.webprojeto.cadastro;

import java.util.List;

import br.com.webprojeto.basicas.Juridica;
import br.com.webprojeto.cadastro.interfaces.InterfaceCadastroJuridica;
import br.com.webprojeto.exception.CnpjDuplicadoException;
import br.com.webprojeto.interfaces.*;

public class CadastroJuridica implements InterfaceCadastroJuridica {

	// atributos primarios de interface

	private InterfaceColecaoJuridica juridica;

	// contrutores

	public CadastroJuridica(InterfaceColecaoJuridica juridica) {
		super();
		this.juridica = juridica;
	}

	// metodos delegados

	/* (non-Javadoc)
	 * @see br.com.webprojeto.cadastro.InterfaceCadastroJuridica#adicionarJuridica(br.com.webprojeto.basicas.Juridica)
	 */
	@Override
	public void adicionarJuridica(Juridica jud) throws CnpjDuplicadoException {
		
		if(localizarJuridicaCnpj(jud.getCnpj())== null ){
		juridica.adicionarJuridica(jud);
		}else{
			CnpjDuplicadoException ex = new CnpjDuplicadoException(jud.getCnpj());
			throw ex;
		}
	}

	/* (non-Javadoc)
	 * @see br.com.webprojeto.cadastro.InterfaceCadastroJuridica#removerJuridica(long)
	 */
	@Override
	public void removerJuridica(long codJuridica) {
		juridica.removerJuridica(codJuridica);
	}

	/* (non-Javadoc)
	 * @see br.com.webprojeto.cadastro.InterfaceCadastroJuridica#atualizarJuridica(br.com.webprojeto.basicas.Juridica)
	 */
	@Override
	public void atualizarJuridica(Juridica jud) {
		juridica.atualizarJuridica(jud);
	}

	/* (non-Javadoc)
	 * @see br.com.webprojeto.cadastro.InterfaceCadastroJuridica#listarJuridica()
	 */
	@Override
	public List<Juridica> listarJuridica() {
		return juridica.listarJuridica();
	}

	/* (non-Javadoc)
	 * @see br.com.webprojeto.cadastro.InterfaceCadastroJuridica#procurarJuridica(long)
	 */
	@Override
	public Juridica procurarJuridica(long codJuridica) {
		
		return juridica.procurarJuridica(codJuridica);
		
	}

	/* (non-Javadoc)
	 * @see br.com.webprojeto.cadastro.InterfaceCadastroJuridica#localizarJuridicaCnpj(java.lang.String)
	 */
	@Override
	public Juridica localizarJuridicaCnpj(String cnpj) {
		return juridica.localizarJuridicaCnpj(cnpj);
	}

}
